﻿namespace IronLua

open System
open System.IO
open IronLua.Parsing
open IronLua.Runtime

type ClrThread = System.Threading.Thread

type Lua() = 
    class
        let _env = LuaState.Instance.Environ |> LuaValue.FromClrValue
        let thread = new Thread(LuaState.Instance, _env)        
                
        member private this.Eval(fn : IClosure, args : obj seq) =
            fn.ClrInvoke(args)                
                                        
        member this.Eval(src : string) =
            this.Eval(src, Seq.empty)

        member this.Eval(src : string, args : obj seq) =
            let fn = Compiler.Compile(thread, thread.Environ, src)
            this.Eval(fn, args)

        member this.Eval(src : string, name : string) =    
            this.Eval(src, name, Seq.empty)
               
        member this.Eval(src : string, name : string, args : obj seq) =             
            let fn = Compiler.Compile(thread, thread.Environ, name, src)
            this.Eval(fn, args)

        interface IDisposable with
            member this.Dispose() = this.Dispose(true)

        member private this.Dispose(disposing : bool) = 
            if disposing 
            then ()
            else ()

    end

